#include "Smtp.h"

#include <iostream>

using tcp = boost::asio::ip::tcp;  // from <boost/asio/ip/tcp.hpp>

namespace smtp {
    Smtp::Smtp(std::string host, std::string port)
        : io_context(),
          resolver(io_context),
          stream(io_context) {
        tcp::resolver resolver(io_context);
        auto          endpoints = resolver.resolve(host, port);

        boost::system::error_code      error = boost::asio::error::host_not_found;
        stream.connect(*endpoints.begin(), error);
        if (error) {
            stream.close();
            std::runtime_error("HOST can't be connected!!");
        }
        else {
            // 读取连接成功问候响应
            std::cout << get_response() << std::endl;
        }
    }

    Smtp::~Smtp() {
    }

    void Smtp::send(const std::string& msg) {
        SmtpBase::send(stream, msg);
    }

    std::string Smtp::get_response() {
        return SmtpBase::get_response(stream);
    }
}  // namespace smtp